﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using DevComponents.DotNetBar;
using System.Windows.Forms;
using DiBang.Sql;
using DiBang.Common;

namespace ChangWuDiBang
{
    public partial class FrmLogin : Office2007Form
    {
        public UserInfo _UserInfo
        {
            get;
            set;
        }

        public FrmLogin()
        {
            this.EnableGlass = false;
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            UserInfoCheck();
        }

        private void txtPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                UserInfoCheck();
            }
        }

        private void UserInfoCheck()
        { 
            if(string.IsNullOrEmpty(txtUserID.Text.Trim()))
            {
                MessageBoxEx.Show("用户名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtUserID.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txtPwd.Text.Trim()))
            {
                MessageBoxEx.Show("密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtPwd.Focus();
                return;
            }

            SqlExtend sqlextend = new SqlExtend();

            if (sqlextend.UserPwdCheck(txtUserID.Text.Trim(), txtPwd.Text.Trim()))
            {
                //需要将_UserInfo传入FrmMain中
                this._UserInfo = sqlextend.GetUserInfo(txtUserID.Text.Trim());
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBoxEx.Show("用户名和密码不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //this.DialogResult = DialogResult.Cancel;
                txtPwd.Clear();
                txtPwd.Focus();
                //this.Close();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
